{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "# 初期設定"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "## Ubuntu16.04\n",
    "\n",
    "### 日本語設定\n",
    "\n",
    "* 公式dockerイメージで日本語が入ってない場合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ja_JP.UTF-8\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "#sudo apt-get install -y language-pack-ja-base language-pack-ja ibus-mozc fonts-takao-gothic\n",
    "#update-locale LANG=ja_JP.UTF-8 LANGUAGE=\"ja_JP:ja\"\n",
    "source /etc/default/locale\n",
    "echo $LANG"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "deletable": true,
    "editable": true
   },
   "source": [
    "### 日本時刻設定"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false,
    "deletable": true,
    "editable": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      Local time: Thu 2017-06-15 17:59:29 JST\n",
      "  Universal time: Thu 2017-06-15 08:59:29 UTC\n",
      "        RTC time: Thu 2017-06-15 08:59:30\n",
      "       Time zone: Asia/Tokyo (JST, +0900)\n",
      " Network time on: yes\n",
      "NTP synchronized: yes\n",
      " RTC in local TZ: no\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "#sudo timedatectl set-timezone Asia/Tokyo\n",
    "sudo timedatectl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "module.js:487\n",
      "    throw err;\n",
      "    ^\n",
      "\n",
      "Error: Cannot find module 'jsdom'\n",
      "    at Function.Module._resolveFilename (module.js:485:15)\n",
      "    at Function.Module._load (module.js:437:25)\n",
      "    at Module.require (module.js:513:17)\n",
      "    at require (internal/module.js:11:18)\n",
      "    at Object.<anonymous> (/root/python/jupyter_notebook/sample.js:1:77)\n",
      "    at Module._compile (module.js:569:30)\n",
      "    at Object.Module._extensions..js (module.js:580:10)\n",
      "    at Module.load (module.js:503:32)\n",
      "    at tryModuleLoad (module.js:466:12)\n",
      "    at Function.Module._load (module.js:458:3)\n"
     ]
    }
   ],
   "source": [
    "%%bash\n",
    "source /etc/default/locale\n",
    "source ~/.nvm/nvm.sh\n",
    "js=sample.js\n",
    "\n",
    "\n",
    "### サンプルファイルの作成\n",
    "cat <<- 'EOS' > ${js}\n",
    "const jsdom = require(\"jsdom\");\n",
    "const { JSDOM } = jsdom;\n",
    "const { window } = new JSDOM(`<!DOCTYPE html>`);\n",
    "const $ = require('jquery')(window);\n",
    "const { TextEncoder } = require(\"./encoding.min.js\");\n",
    "\n",
    "$(function() {\n",
    "\n",
    "  // UTF-16がそのままエスケープされ \"%u3042\" になる\n",
    "  console.log(escape(\"あ\"));\n",
    "  \n",
    "  // UTF-8に変換されて \"%E3%81%82\" になる\n",
    "  console.log(encodeURI(\"あ\"));\n",
    "  console.log(encodeURIComponent(\"あ\"));  \n",
    "\n",
    "  var encoder = new TextEncoder(\"utf-8\"),    // utf-8のエンコーダ(文字列→Uint8Array変換)を作成\n",
    "  u8array = encoder.encode(\"あいうえお\"), // => Uint8Array[240, 128, 128, 128, 240, 128, 128, 128, 240, 128, 128, 128, 240, 128, 128, 128, 240, 128, 128, 128]\n",
    "  deocder = new TextDecoder(\"utf-8\"),    // utf-8のデコーダ(Uint8Array→文字列)を作成\n",
    "  decodedText = decoder.decde(u8array); \n",
    "    \n",
    "});\n",
    "EOS\n",
    "\n",
    "### 実行\n",
    "node ${js}"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
